#include "l3g4200d.h"

//************初始化L3G4200D*********************************


//L3G4200D内部寄存器
#define CTRL_REG1 0x20
#define CTRL_REG2 0x21
#define CTRL_REG3 0x22
#define CTRL_REG4 0x23
#define CTRL_REG5 0x24
#define OUT_X_L 0x28
#define OUT_X_H 0x29
#define OUT_Y_L 0x2A
#define OUT_Y_H 0x2B
#define OUT_Z_L 0x2C
#define OUT_Z_H 0x2D
unsigned char BUF[8];        //接收数据缓存区
short T_X,T_Y,T_Z;
                 
void Init_L3G4200D(void)
{
	Sensors_I2C_WriteRegister(L3G4200_Addr,CTRL_REG1,1,(unsigned char *)0x0f);
	Sensors_I2C_WriteRegister(L3G4200_Addr,CTRL_REG2,1,(unsigned char *)0x00);
	Sensors_I2C_WriteRegister(L3G4200_Addr,CTRL_REG3,1,(unsigned char *)0x08);
	Sensors_I2C_WriteRegister(L3G4200_Addr,CTRL_REG4,1,(unsigned char *)0x30);	//+-2000dps
	Sensors_I2C_WriteRegister(L3G4200_Addr,CTRL_REG5,1,(unsigned char *)0x00);
}	
//******读取L3G4200D数据****************************************
void read_L3G4200D(void)
{I2cMaster_Init();
		BUF[0]=Sensors_I2C_ReadRegister(L3G4200_Addr,OUT_X_L,1,&BUF[0]);
		BUF[1]=Sensors_I2C_ReadRegister(L3G4200_Addr,OUT_X_H,1,&BUF[1]);
		T_X=	(BUF[1]<<8)|BUF[0];



		BUF[2]=Sensors_I2C_ReadRegister(L3G4200_Addr,OUT_Y_L,1,&BUF[2]);
		BUF[3]=Sensors_I2C_ReadRegister(L3G4200_Addr,OUT_Y_H,1,&BUF[3]);
		T_Y=	(BUF[3]<<8)|BUF[2];


		BUF[4]=Sensors_I2C_ReadRegister(L3G4200_Addr,OUT_Z_L,1,&BUF[4]);
		BUF[5]=Sensors_I2C_ReadRegister(L3G4200_Addr,OUT_Z_H,1,&BUF[5]);
		T_Z=	(BUF[5]<<8)|BUF[4];
		printf("\r\n read_L3G4200D_x:%d \r\n",T_X);
		printf("\r\n read_L3G4200D_y:%d \r\n",T_Y);
		printf("\r\n read_L3G4200D_z:%d \r\n",T_Z);
}




